#!/bin/bash
#shell script to zip up a couple of log files, as well as any cores 
#and javacores found on system.

datelabel=$(date +%m%d%Y%H%M%S)

#generate javacore files
echo Would you like to generate javacore files. Please type yes or no.
read answer
if [ $answer = yes ]
then

  for i in CIMClient WConsole ServerT VtermServerStart CIMServer VconsTerminal
  do

    STOP_PID=`ps -efww | grep $i | grep -v grep | cut -c10-16`
    echo $STOP_PID
    if [ "$STOP_PID" != "" ]
    then
        echo Sending SIGQUIT to $i
	kill -3 $STOP_PID > /dev/null 2>&1
        # wait (with timeout) 
        for j in 1 2 3 4 5 6
        do
                if ps -efww | grep $i > /dev/null 2>&1 
                then
                        sleep 1
                else
                        break
                fi
        done
    fi

  done
fi

#remove any existing /tmp/HSClogs.zip file and /tmp/sysinfo.log file
rm -f /tmp/HSClogs$datelabel.zip 2>/dev/null
rm -f /tmp/sysinfo.log 2>/dev/null

#make a new /tmp/sysinfo.log file
file=/tmp/sysinfo.log
echo *************SYSTEM INFORMATION************** >> $file
date +"%a %b %e %r %Z %Y" >> $file
echo >> $file
echo Disk Usage: >> $file
echo ----------- >> $file
df >> $file
echo >> $file
echo Memory and Swap Usage: >> $file
echo ---------------------- >> $file
free -b >> $file
echo >> $file
echo Top 30 Processes Using the Most Memory >> $file
echo -------------------------------------- >> $file
ps auwwwx | sort +4 -5 +9 -10 -r -n | head -30 >> $file
echo >> $file
echo Top 30 Processes Using the Most CPU Time >> $file
echo ---------------------------------------- >> $file
ps auwwwx | sort +2 -3 +9 -10 -r -n | head -30 >> $file
echo >> $file


#zip everything up into /tmp/HSClogs.zip.
zip -gj /tmp/HSClogs$datelabel.zip /var/hsc/log/iqyylog.log /opt/hsc/data/iqzdtrac.trm /opt/hsc/data/iqzdtrac.trm.previous /var/log/messages /tmp/sysinfo.log

zip -gD /tmp/HSClogs$datelabel.zip /var/ct/IW/log/mc/IBM.ServiceRM/* /var/ct/IW/log/mc/IBM.DMSRM/* /var/ct/IW/log/mc/trace

for mntpoint in `/bin/df -l -m | /usr/bin/tail +2 | /bin/awk '{print $6}'`
do
   for n in `/usr/bin/find $mntpoint \( -name core -o -name javacore* \) -xdev -type f`
   do
      zip -gj /tmp/HSClogs$datelabel.zip $n
   done
done
 
#either copy HSClogs.zip to a DVD, or just leave it in /tmp dir 
echo Would you like to move zip file to a DVD?  Please type yes or no.
read answer
if [ $answer = yes ]
then
   umount /mnt/cdrom
   mount /mnt/cdrom
   cp /tmp/HSClogs$datelabel.zip /mnt/cdrom
   if [ $? -eq 0 ]
   then
      echo HSClogs$datelabel.zip placed on DVD. 
      umount /mnt/cdrom
      rm /tmp/HSClogs$datelabel.zip
   fi
else
  echo HSClogs$datelabel.zip created in /tmp directory.
fi
  
